using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using limpalex.bbparser.Interfaces;

namespace limpalex.bbparser
{
    public class ReflectionAttributeEvaluator : IAttributeEvaluator
    {
        private MethodInfo _evaluateMethod;
        public string EvaluateAttribute(IParameterList parameters, string name)
        {
            return (string) _evaluateMethod.Invoke(null, new object[] {parameters, name});
        }

        public string[] SupportedAttributes { get; private set; }

        public static ReflectionAttributeEvaluator Create
            (string[] supportedAttributes, string evaluateMethod, string evaluateMethodType)
        {
            var retval = new ReflectionAttributeEvaluator { SupportedAttributes = supportedAttributes };

            var type = Type.GetType(evaluateMethodType);
            retval._evaluateMethod = type.GetMethod
                (evaluateMethod, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, 
                    null, new[] {typeof (IParameterList), typeof (string)}, null);
            return retval;
        }

        private ReflectionAttributeEvaluator()
        {
            
        }
    }
}
